package com.wh.concurrent.deadlock;

//模拟了线程的死锁
public class Deadlock {

	private String obj;
	
	public Deadlock(String obj) {
		this.obj = obj;
	}
	
	public synchronized void check1(Deadlock o) {
		System.out.println("进入对象:" + obj);
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		o.check2();
		System.out.println("结束对象的执行:" + obj);
	}
	
	public synchronized void check2() {
		System.out.println("运行了check2方法");
	}
	
	public static void main(String[] args) {
		final Deadlock obj1 = new Deadlock("obj1");
		final Deadlock obj2 = new Deadlock("obj2");
		new Thread(){
			@Override
			public void run() {
				obj1.check1(obj2);
			}
			
		}.start();
		new Thread() {
			@Override
			public void run() {
				obj2.check1(obj1);
			}
		}.start();
		System.out.println("主线程结束！");
	}
} 
